﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cricket.LinqData;
using Cricket.LinqModel;

public partial class AddBettingType : System.Web.UI.Page
{
    #region Variable Declaration
    IDataRepository _dataObject = new DataRepository();
    BettingType bettingType;
    List<BettingType> bettingTypes;
    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //if (Session["AdminUser"] != null)
            //    SessionManager.CurrentUser = (LoggedInUser)Session["AdminUser"];
            HttpCookie cookie = Request.Cookies["Admin"];
            if (cookie == null)
            {
                Response.Redirect("Login.aspx");
            }
            if (Request.QueryString["Id"] != null)
            {
                fillBettingType(Request.QueryString["Id"].ToString());
            }
        }
    }

    private void fillBettingType(string BettingId)
    {
        bettingType = new BettingType(_dataObject);
        bettingType.Id = Convert.ToInt32(BettingId);
        bettingType.GetBettingTypeById();
        if (bettingType.Id != 0)
        {
            txtType.Text = bettingType.Type;            
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        bettingType = new BettingType(_dataObject);
        bettingType.Type = txtType.Text;
        bettingType.IsActive = true;
        bettingType.IsDeleted = false;
        
        if (Request.QueryString["Id"] != null)
        {
            bettingType.DateUpdated = System.DateTime.UtcNow;
            bettingType.Id = Convert.ToInt32(Request.QueryString["Id"].ToString());
            bettingType.UpdateBettingType();
            Response.Redirect("ViewBettingType.aspx");
            //layerSuccess.InnerHtml = "<strong>Success!</strong> Betting type updated successfully.";
            //layerSuccess.Attributes.Add("style", "display:block;");
        }
        else
        {
            bettingType.DateAdded = System.DateTime.UtcNow;
            bettingType.Create();
            layerSuccess.InnerHtml = "<strong>Success!</strong> Betting type added successfully.";
            layerSuccess.Attributes.Add("style", "display:block;");
        }
        clearControl();
    }

    private void clearControl()
    {
        txtType.Text = string.Empty;
    }
    protected void btnView_Click(object sender, EventArgs e)
    {
        Response.Redirect("ViewBettingType.aspx");
    }
}